#!/usr/bin/python3.8.9
# -*- coding: utf-8 -*-

# @Author  : Tina Yu
# @Time    : 2021-7-11 22:33
'''
这是一个父类-汽车和子类-电动汽车.
'''


class Car:
    def __init__(self, make, model, year):
        self.make = make
        self.model = model
        self.year = year
        self.odometer_reading = 0

    def get_descriptive_name(self):
        long_name = f'{self.year} {self.make} {self.model}'
        return long_name.title()

    def read_odometer(self):
        print(f'This car has {self.odometer_reading} miles on it.')

    def update_odometer(self, mileage):
        if mileage >= self.odometer_reading:
            self.odometer_reading = mileage
        else:
            print("You can't roll back an odometer！")

    def increment_odometer(self, miles):
        self.odometer_reading += miles

    def fill_gas_tank(self):
        print('这是Car类中的一个无用方法！')


# 实例用作属性
class Battery:
    def __init__(self, battery_size):
        self.battery_size = battery_size

    def describe_battery(self):
        print(f'Battery类中重写的方法：This car has a {self.battery_size}-kWh battery.')

    def get_range(self):
        '''打印一条消息，指出电瓶的续航里程'''
        if self.battery_size == 75:
            range_miles = 260
        elif self.battery_size == 100:
            range_miles = 315
        print(f'属性用作实例：This car can go about {range_miles} miles on a full charge.')

    # 练习9-9【电瓶升级】
    def upgrade_battery(self):
        if self.battery_size != 100:
            self.battery_size = 100
            print("Upgraded the battery to 100 kWh.")
        else:
            print("The battery is already upgraded.")


# 继承
class ElectricCar(Car):
    def __init__(self, make, model, year, battery_size):
        '''初始化父类的属性'''
        super().__init__(make, model, year)
        self.battery = Battery(battery_size)

    def describe_battery(self):
        print(f'ElectricCar类中的方法：This car has a {self.battery.battery_size}-kWh battery.')

    def fill_gas_tank(self):
        print('这是子类中重写的方法！')
